package top.superflow.flow.inner

import org.springframework.context.ApplicationContext
import top.superflow.exception.RequestUnsupportedException
import top.superflow.flow.runtime.resource.RuntimeResource

class InnerSpringRuntimeResource extends RuntimeResource{

  private var applicationContext : ApplicationContext = _

  def setApplicationContext(applicationContext: ApplicationContext): Unit ={
    this.applicationContext = applicationContext
  }

  override def get[T](clz : Class[T]): T ={

    return try {
      this.applicationContext.asInstanceOf[T]
    } catch {
      case ce : ClassCastException => throw new RequestUnsupportedException("Are you sure you know the type of the resource", ce)
    }

  }

  def get : ApplicationContext = {
    this.applicationContext
  }

}
